// Copyright 2010 Alexandre Tristan St-Cyr <tristan.stcyr@gmail.com>

package com.codeplex.loadjava.model;

import org.objectweb.asm.Type;


public class Method {
	
	private JavaClass javaClass;
	
	private String descriptor;
	
	private String name;
	
	public Method(JavaClass javaClass, String name, String descriptor) {
		this.javaClass = javaClass;
		this.descriptor = descriptor;
		this.name = name;
	}
	
	public JavaClass getDeclaringClass()
	{
		return this.javaClass;
	}
	
	public String getDescriptor()
	{
		return this.descriptor;
	}
	
	public String getName()
	{
		return this.name;
	}
	
	public TypeReference getReturnType()
	{
		return new TypeReference(Type.getReturnType(this.descriptor));
	}
	
	@Override
	public int hashCode()
	{
		return (this.getMangledName()).hashCode();
	}
	
	@Override
	public boolean equals(Object o)
	{
		if (!Method.class.isInstance(o))
			return false;
		Method other = (Method)o;
		return this.javaClass.equals(other.javaClass)
			&& this.descriptor.equals(other.descriptor)
			&& this.name.equals(other.name);
	}
	
	private String getMangledName()
	{
		return this.getDeclaringClass() + "." + this.name 
			+ "." + this.descriptor;
	}
	
	@Override
	public String toString()
	{
		return this.getMangledName();
	}
}
